package com.me.launcher.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.me.launcher.custom.GragGridView;

import java.util.ArrayList;

/**
 * @author hejiangwei
 * 主工作区的页面滑动适配器
 */
public class WorkSpacePagerAdapter extends PagerAdapter {
    ArrayList<GragGridView> mdatas;

    public WorkSpacePagerAdapter(ArrayList<GragGridView> mdatas) {
        this.mdatas = mdatas;
    }

    /**
     * 显示多少个页面
     *
     * @return
     */
    @Override
    public int getCount() {
        return mdatas.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    // 初始化显示的条目对象
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(mdatas.get(position), 0);
        return mdatas.get(position);
    }

    // 销毁条目对象
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}

